package com.hsnn.medstgmini.pro.plan.controller;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.dict.model.DicArea;
import com.hsnn.medstgmini.base.dict.model.DicDrugform;
import com.hsnn.medstgmini.base.dict.model.DicHosptype;
import com.hsnn.medstgmini.base.dict.model.DicSys;
import com.hsnn.medstgmini.base.dict.model.form.DicAreaForm;
import com.hsnn.medstgmini.base.dict.service.DicAreaManager;
import com.hsnn.medstgmini.base.std.model.HospInfo;
import com.hsnn.medstgmini.base.std.model.StdCompinfo;
import com.hsnn.medstgmini.base.std.model.StdDrugInfo;
import com.hsnn.medstgmini.pro.plan.model.BidHospplan;
import com.hsnn.medstgmini.pro.plan.model.form.BidCollectByHospForm;
import com.hsnn.medstgmini.pro.plan.model.form.BidProjByDrugForm;
import com.hsnn.medstgmini.pro.plan.service.BidHospplanManager;
import com.hsnn.medstgmini.pro.project.model.BidProject;
import com.hsnn.medstgmini.pro.project.service.BidProjCompanyManager;
import com.hsnn.medstgmini.pro.project.service.BidProjectManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.AreaUtil;
import com.hsnn.medstgmini.util.DateUtil;
import com.hsnn.medstgmini.util.DicSysUtil;
import com.hsnn.medstgmini.util.Pagination;

@Controller
@RequestMapping("/bidHospplan")
public class BidHospplanController {
	@Autowired
	private BidHospplanManager bidHospplanManager;
	@Autowired
	private BidProjectManager bidProjectManager;
	@Autowired
	private  HttpServletRequest request;
	@Autowired
	private BidProjCompanyManager bidProjCompanyManager;
	@Autowired
	private DicAreaManager dicAreaManager;
	@Value("#{sysProp['system.province']}")
	private String sysProvince;
	
	@Value("#{sysProp['system.purProportion']}")
	private String purProportion;
	
	@RequestMapping("/toList")
	public String toList(){
		request.setAttribute("projId", request.getParameter("projId"));
		return "/pro/plan/bidHospPlanList";
	}
	
	@RequestMapping("/toProdrugCataDetail")
	public String toProdrugCataDetail(){
		request.setAttribute("hospId", request.getParameter("hospId"));
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("projPlanId", request.getParameter("projPlanId"));
		
		BidProject bp = bidProjectManager.getBidProjectById(request.getParameter("projId"));
		request.setAttribute("projName", bp.getName());
		return "/pro/plan/prodrugCataDetail";
	}
	
	/**
	 * 
	 *@category 获取当前医疗机构申报计划列表数据
	 *@author 邱磊
	 *@date 2015年6月12日 下午3:09:16
	 *@return
	 */
	@RequestMapping("/getDataList")
	@ResponseBody
	public Pagination getDataList(){
		Pagination page = new Pagination(request);
		if (null != request.getParameter("projCode") && !"".equals(request.getParameter("projCode").trim())){
			page.getConditions().put("projCode", request.getParameter("projCode").trim());
		}
		if (null != request.getParameter("name") && !"".equals(request.getParameter("name").trim())){
			page.getConditions().put("name", request.getParameter("name").trim());
		}
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String hospCode = ((HospInfo )user.getInfo()).getHospCode();
		page.getConditions().put("hospCode", hospCode);
		page = bidHospplanManager.getDataList(page);
		return page;
	}
	
	@RequestMapping("/toDrugList")
	public String toDrugList(){
		List<DicSys> proCatList = DicSysUtil.getDicListByClassCode(Constants.PRO_METHOD);
		BidProject bp = bidProjectManager.getBidProjectById(request.getParameter("projId"));
		request.setAttribute("projName", bp.getName());
		request.setAttribute("proCatList", proCatList);
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("purProportion", purProportion);
		return "/pro/plan/drugNotDeclareList";
	}
	/**
	 * 
	 *@category 获取当前医疗机构未申报的药品
	 *@author 邱磊
	 *@date 2015年6月12日 下午4:53:01
	 *@return
	 */
	@RequestMapping("/getDrugDataList")
	@ResponseBody
	public Pagination getDrugDataList(){
		Pagination page = new Pagination(request);
		if (null != request.getParameter("drugCode") && !"".equals(request.getParameter("drugCode").trim())){
			page.getConditions().put("drugCode", request.getParameter("drugCode").trim());
		}
		if (null != request.getParameter("drugName") && !"".equals(request.getParameter("drugName").trim())){
			page.getConditions().put("drugName", request.getParameter("drugName").trim());
		}
		if (null != request.getParameter("prodPompId") && !"".equals(request.getParameter("prodPompId").trim())){
			page.getConditions().put("prodPompId", request.getParameter("prodPompId").trim());
		}
		
		if (StringUtils.isNotBlank(request.getParameter("compName"))) {
			page.getConditions().put("compName", request.getParameter("compName").trim());
		}
		
		if (null != request.getParameter("projId") && !"".equals(request.getParameter("projId").trim())){
			page.getConditions().put("projId", request.getParameter("projId").trim());
		}
		SysUser user = (SysUser) request.getSession().getAttribute(Constants.USERINFO);
		page.getConditions().put("hospCode", ((HospInfo)user.getInfo()).getHospCode());
		page = bidHospplanManager.getDrugDataList(page);
		return page;
	}
	
	/**
	 *@category 获取当前医疗机构已申报的药品
	 *@author 应晓川
	 *@date 2015年6月28日 
	 *@return
	 */
	@RequestMapping("/gotDrugDataList")
	@ResponseBody
	public Pagination gotDrugDataList(){

		Pagination page = new Pagination(request);
		if (null != request.getParameter("drugCode") && !"".equals(request.getParameter("drugCode").trim())){
			page.getConditions().put("drugCode", request.getParameter("drugCode").trim());
		}
		if (null != request.getParameter("drugName") && !"".equals(request.getParameter("drugName").trim())){
			page.getConditions().put("drugName", request.getParameter("drugName").trim());
		}
		if (null != request.getParameter("prodPompId") && !"".equals(request.getParameter("prodPompId").trim())){
			page.getConditions().put("prodPompId", request.getParameter("prodPompId").trim());
		}
		if (null != request.getParameter("projId") && !"".equals(request.getParameter("projId").trim())){
			page.getConditions().put("projId", request.getParameter("projId").trim());
		}
		if (null != request.getParameter("hospId") && !"".equals(request.getParameter("hospId").trim())){
			page.getConditions().put("hospId", request.getParameter("hospId").trim());
		}
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String hospCode = ((HospInfo )user.getInfo()).getHospCode();
		page.getConditions().put("hospCode", hospCode);
		page = bidHospplanManager.gotDrugDataList(page);
		return page;
	}
	
	
	@RequestMapping("/batchAddDrugData")
	@ResponseBody
	public Pagination batchAddDrugData(String array){
		Pagination page = new Pagination(request);
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO); 
		HospInfo hospinfo = ((HospInfo)user.getInfo());
		String hospCode = hospinfo.getHospCode();
		String areId = ((HospInfo)user.getInfo()).getArea().getAreaid();
		String updDatetime = DateUtil.dateTime(new Timestamp(System.currentTimeMillis()));
		try {
			
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<Map<String,String>>>() {
				}.getType();
				List<Map<String,String>> list = gson.fromJson(array, type);
				if (list != null && !list.isEmpty()) {
					for (Map<String,String> data : list) {
						data.put("hospCode", hospCode);
						data.put("userId", user.getId());
						data.put("areaId", areId);
						data.put("updDatetime", updDatetime);
					}
					page.setOperCount(bidHospplanManager.batchAddDrugData(list));
					page.setSuccess(true);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 跳向已启用的采购计划空页面
	 * @author 张俊
	 * @param 
	 * @return
	 */
	@RequestMapping("/toProjList")
	public String toProjList() {
		return "/pro/plan/bidProjList";
	}
	/**
	 * @category 查询已启用的采购计划列表
	 * @author 张俊
	 * @param result
	 * @param bidProjCompany
	 * @param stdCompinfo
	 * @return
	 */
	@RequestMapping("/getProjDataList")
	@ResponseBody
	public Pagination getBidProjectList(BidProject bidProject) {
		Pagination page = new Pagination(request);
		try {
			List<BidProject> list = bidProjectManager.getBidProjectList(page, bidProject);
			page.setRows(list);
			page.setSuccess(true);
		} catch (Exception e) {
			//log.error(e);
			page.setSuccess(false);
		}
		return page;
	}
	
	@RequestMapping("/toProjByDrugList")
	public String toProjByDrugList() throws UnsupportedEncodingException {
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("projName", URLDecoder.decode(request.getParameter("projName"), "utf-8"));
		return "/pro/plan/bidProjByDrugList";
	}
	
	/**
	 * @category 采购计划按药品汇总
	 * @author 张俊
	 * @param bidHospplan
	 * @param bidProject
	 * @param stdDrugInfo
	 * @param hospInfo
	 * @param dicDrugform
	 * @param stdCompinfo
	 * @return
	 */
	@RequestMapping("/getProjByDrugList")
	@ResponseBody
	public Pagination getProjByDrugList(BidHospplan bidHospplan, BidProject bidProject, StdDrugInfo stdDrugInfo, HospInfo hospInfo, DicDrugform dicDrugform, StdCompinfo stdCompinfo) {
		Pagination page = new Pagination(request);
		try {
			List<BidProjByDrugForm> list = bidHospplanManager.getBidHospplanList(page, bidHospplan, bidProject, stdDrugInfo, hospInfo, dicDrugform, stdCompinfo);
			page.setRows(list);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	@RequestMapping("/toPlanListByDrug")
	public String toPlanListByDrug () {
		DicAreaForm area = dicAreaManager.getDicAreaById(sysProvince);
		request.setAttribute("area", area);
		request.setAttribute("sysAreaId", sysProvince);
		request.setAttribute("projName", request.getParameter("projName"));
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("drugId", request.getParameter("drugId"));
		request.setAttribute("drugName", request.getParameter("drugName"));
		request.setAttribute("formName", request.getParameter("formName"));
		request.setAttribute("specName", request.getParameter("specName"));
		request.setAttribute("factor", request.getParameter("factor"));
		request.setAttribute("unit", request.getParameter("unit"));
		request.setAttribute("materialName", request.getParameter("materialName"));
		request.setAttribute("compName", request.getParameter("compName"));
		return "/pro/plan/bidPlanListByDrug";
	}
	/**
	 * @category 采购计划按药品汇总详情
	 * @author 单大伟
	 * @param bidHospplan
	 * @param HospInfo
	 * @param dicArea
	 * @param dicHosptype
	 * @return
	 */
	@RequestMapping("/getPlanListByDrug")
	@ResponseBody
	public Pagination getPlanListByDrug(BidHospplan bidHospplan, HospInfo HospInfo, DicHosptype dicHosptype) {
		Pagination page = new Pagination(request);
		try {
			String area1 = sysProvince;
			String area2 = request.getParameter("area2");
			String area3 = request.getParameter("area3");
			String areaId=AreaUtil.getAreaStartCode(area1, area2, area3);
			DicArea dicArea = new DicArea();
			dicArea.setAreaid(areaId);
			List<BidProjByDrugForm> list = bidHospplanManager.getBidPlanListByDrug(page, bidHospplan, HospInfo, dicArea, dicHosptype);
			page.setRows(list);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 跳转到配送企业列表页面(医疗机构)
	 * @author 韩守松
	 * @date   2015年6月15日
	 * @param  @return
	 */
	@RequestMapping("/toListJsp")
	public String toBidListJsp(Model model){
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO); 
		String hospId =((HospInfo)user.getInfo()).getHospId();
		Object obj = bidProjectManager.getBidProjectListByCompId(hospId,user.getType().toString());
		model.addAttribute("projList", obj);
		return "/pro/plan/bidBidHospplanCheckList";
	}
	
	/**
	 * @category 获取项目中有效的配送企业
	 * @date 2015年11月19日
	 * @param compInfo
	 * @return
	 */
	@RequestMapping("/getBidDataList")
	@ResponseBody
	public Pagination getBidDataList(StdCompinfo compInfo) {
		Pagination page = new Pagination(request);
		page.setForm(compInfo);
		bidProjCompanyManager.getProjCompList(page);
		page.setSuccess(true);
		return page;
	}
	
	
	/**
	 * 
	 *@category  跳转到采购计划按医疗机构汇总页面
	 *@author 单大伟
	 * @throws UnsupportedEncodingException 
	 *@date 2015年6月18日
	 *String
	 */
	@RequestMapping("/toBidCollectByHospList")
	public String toBidCollectByHospList() throws UnsupportedEncodingException {
		request.setAttribute("projId", request.getParameter("projId"));
		if (StringUtils.isNotBlank(request.getParameter("projName"))) {
		    request.setAttribute("projName", URLDecoder.decode(request.getParameter("projName"), "utf-8"));
		}
		DicAreaForm area = dicAreaManager.getDicAreaById(sysProvince);
		request.setAttribute("area", area);
		return "/pro/plan/bidCollectByHosp";
	}
	
	/**
	 * 
	 *@category	获取采购计划按医疗机构汇列表及查询
	 *@author 言科
	 *@date 2015年6月18日
	 *Pagination
	 */
	@RequestMapping("/getBidCollectByHospList")
	@ResponseBody
	public Pagination getBidCollectByHospList(BidHospplan bidHospplan, BidProject bidProject, HospInfo hospInfo,
			DicHosptype dicHosptype, DicArea dicArea){
		Pagination page = new Pagination(request);
		String area1 = sysProvince;
		String area2 = request.getParameter("area2");
		String area3 = request.getParameter("area3");
		String areaId=AreaUtil.getAreaStartCode(area1, area2, area3);
		dicArea.setAreaid(areaId);
		try {
			List<BidCollectByHospForm> list = bidHospplanManager.getBidCollectByHospList(page, bidHospplan, bidProject, hospInfo, dicHosptype, dicArea);
			page.setRows(list);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * 
	 *@category  跳转到采购计划按医疗机构汇总详情页面
	 *@author 单大伟
	 *@date 2015年6月18日
	 *String
	 */
	@RequestMapping("/toBidCollectDetailsByHosp")
	public String toBidCollectDetailsByHosp() {
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("hospId", request.getParameter("hospId"));
		try {
			request.setAttribute("projName", URLDecoder.decode(request.getParameter("projName"), "utf-8"));
			request.setAttribute("hospName", URLDecoder.decode(request.getParameter("hospName"), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "/pro/plan/bidCollectDetailsByHosp";
	}
	
	/**
	 * 
	 *@category	获取采购计划按医疗机构汇列表及查询
	 *@author 言科
	 *@date 2015年6月18日
	 *Pagination
	 */
	@RequestMapping("/getBidCollectDetailsByHosp")
	@ResponseBody
	public Pagination getBidCollectDetailsByHosp(BidHospplan bidHospplan, BidProject bidProject,
			StdDrugInfo stdDrugInfo, HospInfo hospInfo,DicDrugform dicDrugform, StdCompinfo stdCompinfo){
		Pagination page = new Pagination(request);
		try {
			List<BidCollectByHospForm> list = bidHospplanManager.getBidCollectDetailsByHosp(page, bidHospplan, bidProject, stdDrugInfo, hospInfo, dicDrugform, stdCompinfo);
			page.setRows(list);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 配送企业列表页面(医疗机构)弹窗
	 * @author 韩守松
	 * @date   2015年7月15日
	 * @param  @return
	 */
	@RequestMapping("/toPSCompListJsp")
	public String toPSCompListJsp(Model model){
		return "/pro/plan/bidLookHospplanCheckList";
	}
	
	/////////////////////////////////////////////////////////////////////////////////
	/**
	 * @category 跳转分院采购情况查看
	 * @author wangbing
	 * @date   2015年7月15日
	 * @param  @return
	 */
	@RequestMapping("/toBidChildHospPlanList")
	public String toBidChildHospPlanList(){
		return "/pro/plan/bidChildHospPlanList";
	}
	
	/**
	 * @category 分院采购情况查看  获取项目列表
	 * @author wangbing
	 * @date   2015年7月15日
	 * @param  @return
	 */
	@RequestMapping("/getChildHospProjectList")
	@ResponseBody
	public Pagination getChildHospProjectList(){
		Pagination page = new Pagination(request);
		String name = request.getParameter("name");
		String status = request.getParameter("status");
		if(StringUtils.isNotBlank(name)){
			page.getConditions().put("name", name.trim());
		}
		if(StringUtils.isNotBlank(status)){
			page.getConditions().put("status", status.trim());
		}
		try {
			SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO); 
			HospInfo hospInfo = user.getInfo();
			page.setForm(hospInfo);
			bidProjectManager.getChildHospProjectList(page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}
	
	@RequestMapping("/toSeePlanByDrugList")
	public String toSeePlanByDrugList() throws UnsupportedEncodingException {
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("projName", URLDecoder.decode(request.getParameter("projName"), "utf-8"));
		return "/pro/plan/seePlanByDrugList";
	}
	
	/**
	 * @category 分院采购情况查看  获取药品列表
	 * @author wangbing
	 * @date   2015年7月15日
	 * @param  @return
	 */
	@RequestMapping("/getChildHospDrugList")
	@ResponseBody
	public Pagination getChildHospDrugList(){
		Pagination page = new Pagination(request);
		String drugCode = request.getParameter("drugCode");
		String drugName = request.getParameter("drugName");
		String compName = request.getParameter("drugName");
		if(StringUtils.isNotBlank(drugCode)){
			page.getConditions().put("drugCode", drugCode.trim());
		}
		if(StringUtils.isNotBlank(drugName)){
			page.getConditions().put("drugName", drugName.trim());
		}
		if(StringUtils.isNotBlank(compName)){
			page.getConditions().put("compName", compName.trim());
		}
		try {
			page.getConditions().put("projId", request.getParameter("projId"));
			SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO); 
			HospInfo hospInfo = user.getInfo();
			page.setForm(hospInfo);
			bidProjectManager.getChildHospDrugList(page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}
	
	@RequestMapping("/toSeeHospPlanByHosp")
	public String toSeeHospPlanByHosp() throws UnsupportedEncodingException {
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("projName", URLDecoder.decode(request.getParameter("projName"), "utf-8"));
		DicAreaForm area = dicAreaManager.getDicAreaById(sysProvince);
		request.setAttribute("area", area);
		return "/pro/plan/seeHospPlanByHosp";
	}
	
	/**
	 * @category 分院采购情况查看  获取分院列表
	 * @author wangbing
	 * @date   2015年7月15日
	 * @param  @return
	 */
	@RequestMapping("/getChildHospList")
	@ResponseBody
	public Pagination getChildHospList(){
		Pagination page = new Pagination(request);
		String hospCode = request.getParameter("hospCode");
		String hospName = request.getParameter("hospName");
		String hospClassify = request.getParameter("hospClassify");
		String area2 = request.getParameter("area2");
		String area3 = request.getParameter("area3");
		String areaId = AreaUtil.getAreaStartCode(sysProvince, area2, area3);
		page.getConditions().put("areaId", areaId);
		if(StringUtils.isNotBlank(hospCode)){
			page.getConditions().put("hospCode", hospCode.trim());
		}
		if(StringUtils.isNotBlank(hospName)){
			page.getConditions().put("hospName", hospName.trim());
		}
		if(StringUtils.isNotBlank(hospClassify)){
			page.getConditions().put("hospClassify", hospClassify.trim());
		}
		try {
			page.getConditions().put("projId", request.getParameter("projId"));
			SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO); 
			HospInfo hospInfo = user.getInfo();
			page.setForm(hospInfo);
			bidProjectManager.getChildHospList(page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}
	
	@RequestMapping("/toChildHospPlanByDrugDetail")
	public String toChildHospPlanByDrugDetail () {
		DicAreaForm area = dicAreaManager.getDicAreaById(sysProvince);
		request.setAttribute("area", area);
		request.setAttribute("sysAreaId", sysProvince);
		request.setAttribute("projName", request.getParameter("projName"));
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("drugId", request.getParameter("drugId"));
		request.setAttribute("drugName", request.getParameter("drugName"));
		request.setAttribute("formName", request.getParameter("formName"));
		request.setAttribute("specName", request.getParameter("specName"));
		request.setAttribute("factor", request.getParameter("factor"));
		request.setAttribute("unit", request.getParameter("unit"));
		request.setAttribute("materialName", request.getParameter("materialName"));
		request.setAttribute("compName", request.getParameter("compName"));
		return "/pro/plan/bidChildHospPlanByDrugDetail";
	}
	
	/**
	 * 
	 *@category  跳转到采购计划按医疗机构查看详情页面
	 *@author wangbing
	 *@date 2015年6月18日
	 *String
	 */
	@RequestMapping("/toPlanDetailByHosp")
	public String toPlanDetailByHosp() {
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("hospId", request.getParameter("hospId"));
		try {
			request.setAttribute("projName", URLDecoder.decode(request.getParameter("projName"), "utf-8"));
			request.setAttribute("hospName", URLDecoder.decode(request.getParameter("hospName"), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "/pro/plan/bidPlanDetailByHosp";
	}
	
	/**
	 * 
	 *@category  跳转到采购计划按地区汇总页面
	 *@author wangbing
	 * @throws UnsupportedEncodingException 
	 *@date 2015年6月18日
	 *String
	 */
	@RequestMapping("/toBidCollectByAreaList")
	public String toBidCollectByAreaList() throws UnsupportedEncodingException {
		request.setAttribute("projId", request.getParameter("projId"));
		if (StringUtils.isNotBlank(request.getParameter("projName"))) {
		    request.setAttribute("projName", URLDecoder.decode(request.getParameter("projName"), "utf-8"));
		}
		DicAreaForm area = dicAreaManager.getDicAreaById(sysProvince);
		request.setAttribute("area", area);
		return "/pro/plan/bidCollectByArea";
	}
	
	/**
	 * 
	 *@category	获取采购计划按地区列表及查询
	 *@author wangbing
	 *@date 2015年6月18日
	 *Pagination
	 */
	@RequestMapping("/getBidCollectByAreaList")
	@ResponseBody
	public Pagination getBidCollectByAreaList(){
		Pagination page = new Pagination(request);
		String projId = request.getParameter("projId");
		String area2 = request.getParameter("area2");
		String area3 = request.getParameter("area3");
		String areaId = AreaUtil.getAreaStartCode(sysProvince, area2, area3);
		try {
			page.getConditions().put("projId", projId);
			page.getConditions().put("areaId", areaId);
			 bidHospplanManager.getBidCollectByAreaList(page);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * 
	 *@category  跳转到采购计划地区汇总详情页面
	 *@author wangbing
	 *@date 2015年6月18日
	 *String
	 */
	@RequestMapping("/toBidCollectDetailsByArea")
	public String toBidCollectDetailsByArea() {
		request.setAttribute("projId", request.getParameter("projId"));
		request.setAttribute("areaId", request.getParameter("areaId"));
		try {
			request.setAttribute("projName", URLDecoder.decode(request.getParameter("projName"), "utf-8"));
			request.setAttribute("areaName", URLDecoder.decode(request.getParameter("areaName"), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "/pro/plan/bidCollectDetailsByArea";
	}
	
	/**
	 * 
	 *@category	获取采购计划按地区汇总列表及查询
	 *@author wangbing
	 *@date 2015年6月18日
	 *Pagination
	 */
	@RequestMapping("/getBidCollectDetailsByArea")
	@ResponseBody
	public Pagination getBidCollectDetailsByArea(){
		Pagination page = new Pagination(request);
		String projId = request.getParameter("projId");
		String areaId = request.getParameter("areaId");
		String drugCode = request.getParameter("drugCode");
		String drugName = request.getParameter("drugName");
		String compName = request.getParameter("compName");
		String declareIns = request.getParameter("declareIns");
		if(StringUtils.isNotBlank(drugCode)){
			page.getConditions().put("drugCode", drugCode.trim());
		}
		if(StringUtils.isNotBlank(drugName)){
			page.getConditions().put("drugName", drugName.trim());
		}
		if(StringUtils.isNotBlank(compName)){
			page.getConditions().put("compName", compName.trim());
		}
		if(StringUtils.isNotBlank(declareIns)){
			page.getConditions().put("declareIns", declareIns.trim());
		}
		try {
			page.getConditions().put("projId", projId);
			page.getConditions().put("areaId", areaId);
			bidHospplanManager.getBidCollectDetailsByArea(page);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	@RequestMapping("/deleteData")
	@ResponseBody
	public Pagination deleteData(String array){
		Pagination page = new Pagination(request);
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<String>>() {
				}.getType();
				List<String> list = gson.fromJson(array, type);
				page.setOperCount(bidHospplanManager.deleteData(list));
			}
			page.setSuccess(true);
		} catch (Exception e) {
			page.setSuccess(false);
			e.printStackTrace();
		}
		return page;
	}
}
